/*
 * Copyright 2008-2023 dexian.vip. All rights reserved.
 * Support: http://www.dexian.vip
 * License: http://www.dexian.vip/license
 */

package vip.dexian.core.base.mapstruct;

import vip.dexian.core.base.bean.BaseEntity;
import vip.dexian.core.base.command.BaseCommand;
import vip.dexian.core.base.validation.BaseValidator;
import org.mapstruct.BeforeMapping;

import java.io.Serializable;

/**
 * command to entity 转换器
 *
 * @author 挺好的 2023年05月31日 13:31
 */
public abstract class BaseCommandToEntityAssembler<T extends BaseEntity <ID>, S extends BaseCommand, U extends BaseCommand, ID extends Serializable>
        extends BaseValidator {

    @BeforeMapping
    public void validateSave (S command, Class <?>... groups) {
        super.validation(command, groups);
    }

    @BeforeMapping
    public void validateUpdate (U command, Class <?>... groups) {
        super.validation(command, groups);
    }

    /**
     * 将保存指令转换为entity
     *
     * @param command
     *         保存指令
     *
     * @return entity
     */
    public abstract T toSave (S command, Class <?>... groups);

    /**
     * 将更新指令转换为entity
     *
     * @param command
     *         保存指令
     *
     * @return entity
     */
    public abstract T toUpdate (U command, Class <?>... groups);

}
